var e = require("../../../@babel/runtime/helpers/regeneratorRuntime"),
  t = require("../../../@babel/runtime/helpers/slicedToArray"),
  r = require("../../../@babel/runtime/helpers/asyncToGenerator"),
  n = require("../../../config/index"),
  o = require("../../../store/index");
Page({
  data: {},
  onLoad: function () {},
  returnPrevPage: function () {
    $.router.back()
  },
  getPhoneNumber: function (e) {
    this.phoneLogin(e.detail.code)
  },
  phoneLogin(code) {
    wx.login({
      success: (res) => {
        $.request["POST/auth/login"]({
          code: res.code
        }).then(res => {
          wx.setStorageSync('token', res[0].data)
          $.request["POST/auth/regist"]({
            code: code
          }).then(res => {
            var code = res[0].code
            var data = res[0].data
            console.log(data)
            if (code === 20002) {
              wx.setStorageSync('id', data.id)
              wx.setStorageSync('userName', data.userName)
              wx.setStorageSync('userPhone', data.userPhone)
              wx.setStorageSync('avatarUrl', data.avatarUrl)
              $.router.useRouter().interceptNext()
            }
          })
        })
      },
    })
  },
  login: function (a) {
    return r(e().mark((function c() {
      return e().wrap((function (c) {
        for (;;) switch (c.prev = c.next) {
          case 0:
            wx.login({
              success: function () {
                var c = r(e().mark((function r(c) {
                  var i, s, u, d;
                  return e().wrap((function (e) {
                    for (;;) switch (e.prev = e.next) {
                      case 0:
                        if (!c.code) {
                          e.next = 8;
                          break
                        }
                        return i = o.store.getState().storage.INVITECODE, e.next = 4, $.request["POST/user/wx-login-mini?source=XCX"]({
                          data: JSON.stringify({
                            js_tel_code: a,
                            code: c.code
                          }),
                          invite_code: i,
                          source: "XCX"
                        }, {
                          "content-type": "application/json"
                        });
                      case 4:
                        s = e.sent, u = t(s, 1), 200 === (null == (d = u[0]) ? void 0 : d.code) && (d.content.header = d.content.header ? d.content.header : "".concat(n.CDNIMGPATH, "/web/defalut-avatar.png"), (0, o.dispatch)(o.actions.storageActions.setItem({
                          key: "userInfo",
                          value: d.content
                        })), (0, o.dispatch)(o.actions.userActions.setState({
                          userInfo: d.content
                        })), (0, o.dispatch)(o.actions.storageActions.removeItem("INVITECODE")), $.router.useRouter().interceptNext());
                      case 8:
                      case "end":
                        return e.stop()
                    }
                  }), r)
                })));
                return function (e) {
                  return c.apply(this, arguments)
                }
              }()
            });
          case 1:
          case "end":
            return c.stop()
        }
      }), c)
    })))()
  }
});